package net.ocps.tchs.GovSim;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class gameBoard implements Screen {
        screenSwitcher game;
        private OrthographicCamera camera;
        private SpriteBatch batch;
        private Texture texture;
        private Sprite sprite;
         private TextureAtlas atlas;
     private Skin skin;
     private Table table;
     private TextButton buttonExit,buttonPlay;
     private TextButtonStyle Style;
     private BitmapFont font;
     private Stage stage;

        public int var = 2;
        int X = Gdx.input.getX();
        int Y = Gdx.input.getY();
        int clickX=-1;
        int clickY=-1;
        boolean clickyClicky=false;
        boolean clickedAtLeastOnce;

        public gameBoard(screenSwitcher game) {
                this.game = game;
                float w = Gdx.graphics.getWidth();
                float h = Gdx.graphics.getHeight();
        font = new BitmapFont();



                camera = new OrthographicCamera(1, h/w);
                batch = new SpriteBatch();

                
                
                texture = new Texture(Gdx.files.internal("ui/TitleFixed.png"));
                //texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

                TextureRegion button = new TextureRegion(texture, 0, 0, 512, 512);

                sprite = new Sprite(button);
                sprite.setSize(512,512);
        //      sprite.setOrigin(190,130);
                sprite.setPosition(0,0);

                
        }
        @Override
        public void render(float delta) {
                Gdx.gl.glClearColor(1, 1, 1, 1);
                Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                
                 stage.act(delta);
         stage.draw();
         
         
          batch.begin();
          batch.draw(sprite, 0, 0);
          batch.end();  
         // camera.update();
          
                if(Gdx.input.isButtonPressed(0))
                {
                        clickyClicky=true;
                        X = Gdx.input.getX();
                        Y = Gdx.input.getY();
                        
                //      System.out.println("Left Mouse Button" + " " + X + " " + Y);                    

                }
                if(clickyClicky && !Gdx.input.isButtonPressed(0)){
                        clickX = X;
                        clickY=Y;
                        System.out.println("Clicked coords: "+clickX+" "+clickY);
                        
                        clickyClicky=false;
                        clickedAtLeastOnce=true;
//                      clickX=-1;
//                      clickY=-1;
                }
                /*
                 * 
                 *  
                 *  if(clickedAtLeastOnce &&( clickX<250)&&(clickX>190) && (clickY<190)&&(clickY>130) ){
                 System.out.println("Yesssssssssssssssssssssssssssss!");
                          clickX=-1;
                          clickY=-1;
                         }
                         
                 
                 */
                          
                
                
          
                

        }

        @Override
        public void resize(int width, int height) {


        }

        @Override
        public void show() {

                 stage = new Stage();
         Gdx.input.setInputProcessor(stage);
         
         atlas = new TextureAtlas(Gdx.files.internal("ui/button.pack"));
         
         skin = new Skin(atlas);
         
         table = new Table(skin);
         table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
         TextButtonStyle Style = new TextButtonStyle();
         Style.up = skin.getDrawable("button.up");
         Style.down = skin.getDrawable("button.down");
         Style.pressedOffsetX = 1;
         Style.pressedOffsetY = -1;
         Style.font = font;
         
         buttonPlay = new TextButton("Play",Style);
         buttonPlay.pad(20);
         buttonExit = new TextButton("Exit", Style);
         buttonExit.pad(20);
                         
        buttonExit.addListener( new ClickListener() {
           @Override
            public void clicked(InputEvent event, float x, float y) {
               Gdx.app.exit();
            };
        });
        
        buttonPlay.addListener( new ClickListener() {
           @Override
            public void clicked(InputEvent event, float x, float y) {
                   game.setScreen(new gameBoard(game));
            };
        });


        
           
         table.debug();
         table.add(buttonPlay);
         table.add(buttonExit);

         table.pad(20);
        
         
         stage.addActor(table);
         
                         
                
        }

        @Override
        public void hide() {

        }

        @Override
        public void pause() {


        }

        @Override
        public void resume() {


        }

        @Override
        public void dispose() {

        }

}
